package com.dubbo.microserviceweb.response;

public class CommonReturnType {

    //表明对应请求的返回处理结果“success”，“fail”，成功0或者失败1
    private String status;
    //layui 数据表格格式
    private Integer code;
    private Integer count;

    //status = success,data返回前端所需json数据
    //status = fail，data内使用通用的错误码格式
    private Object data;

    //定义一个通用方法
    //controller处理完数据后，调这个静态方法，传入返回数据和对应的状态码
    public static CommonReturnType create(Object result,String status,Integer code,Integer count){
        CommonReturnType type = new CommonReturnType();
        type.setStatus(status);
        type.setData(result);
        type.setCode(code);
        type.setCount(count);
        return type;
    }

    //定义一个默认的成功处理，只传数据的方法，默认认为请求正确
    public static CommonReturnType create(Object result){
        return CommonReturnType.create(result,"success",0,0);
    }
    //定义失败处理
    public static  CommonReturnType create(Object result,String status){
        return  CommonReturnType.create(result,status,0,0);
    }

    //论文分页表格返回
    public  static CommonReturnType createPage(Object result,Integer count){
        return  CommonReturnType.create(result,"success",0,count);
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }
}
